package com.thwj.project.app.api;

import com.thwj.framework.web.domain.R;
import com.thwj.project.app.api.param.AuthRequest;
import com.thwj.project.app.service.WxAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags="app登录鉴权模块")
@RestController
@RequestMapping("/app/auth")
public class AppAuthController {


    @Autowired
    private WxAuthService wxAuthService;

    @ApiOperation(value = "微信小程序登录",notes = "先尝试只传code看是否返回缺少手机号的code=609，如果缺少手机号直接唤起 然后重新获取code+手机号code一起提交 登录成功直接返回 token 添加到header中 Authorization")
    @GetMapping("/wxSmallAppLogin")
    public R<String> wxSmallAppLogin(AuthRequest authRequest) {
        String token = wxAuthService.wxSmallAppLogin(authRequest);
        return R.data(token);
    }


    @ApiOperation(value = "测试生成token 前端无需调用",notes = "")
    @GetMapping("/testCreateToken")
    public R<String> testCreateToken() {
        String token = wxAuthService.testCreateToken();
        return R.data(token);
    }

}
